*Final do file for II
clear 
use "IIreadyforreplication.dta"

*Table 1
*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N1) replace
nbreg pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N2) append

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N3) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N4) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N5) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N6) append

*Generating Predicted Event Counts 

clear 
use IIreadyforreplication.dta

*Run the model

nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)


*Drop observations that are not in the model so that the quantities of interest are not calculated for those observations.

gen keep = 1 if e(sample)
drop if keep ~=1

*Save the data set as a temporary file named temp (you will retrieve this below).

save temp, replace


  set seed 17
  mat b = e(b)
  mat V = e(V)
  drawnorm b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16, mean(b) cov(V) n(1000) clear


sum b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b0
  
  
*Merge the original data set (stored as temp) into the data set containing the simulated coefficients.

merge using temp


gen pmean = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace pmean = r(mean) in `i'
}


drop p_1-p_1000


gen p_0y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*0 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_0y = r(mean) in `i'
}


drop p_1-p_1000

gen p_1y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*1 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_1y = r(mean) in `i'
}


drop p_1-p_1000

gen p_2y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*2 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_2y = r(mean) in `i'
}


drop p_1-p_1000

gen p_3y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*3 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_3y = r(mean) in `i'
}


drop p_1-p_1000

gen p_4y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*4 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_4y = r(mean) in `i'
}


drop p_1-p_1000

gen p_5y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*5 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_5y = r(mean) in `i'
}


drop p_1-p_1000

gen p_6y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*6 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_6y = r(mean) in `i'
}


drop p_1-p_1000

gen p_7y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*7 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_7y = r(mean) in `i'
}


drop p_1-p_1000

gen p_8y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*8 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_8y = r(mean) in `i'
}


drop p_1-p_1000

gen p_9y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*9 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_9y = r(mean) in `i'
}


drop p_1-p_1000

gen p_10y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*10 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_10y = r(mean) in `i'
}


drop p_1-p_1000

gen p_11y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*11 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_11y = r(mean) in `i'
}


drop p_1-p_1000

gen p_12y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*12 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_12y = r(mean) in `i'
}


drop p_1-p_1000

gen p_13y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*13 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_13y = r(mean) in `i'
}


drop p_1-p_1000

gen p_14y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*14 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_14y = r(mean) in `i'
}


drop p_1-p_1000

gen p_15y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*15 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_15y = r(mean) in `i'
}


drop p_1-p_1000

gen p_16y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*16 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_16y = r(mean) in `i'
}


drop p_1-p_1000

gen p_17y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*17 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_17y = r(mean) in `i'
}


drop p_1-p_1000

gen p_18y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*18 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_18y = r(mean) in `i'
}


drop p_1-p_1000

gen p_19y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*19 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_19y = r(mean) in `i'
}


drop p_1-p_1000

gen p_20y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*19 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_20y = r(mean) in `i'
}


drop p_1-p_1000

gen p_21y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*19 + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_21y = r(mean) in `i'
}


drop p_1-p_1000

save predictions.dta

*pull out predicted counts and centiles
*do table program file
do "table_programs.do"
sumtable p_* using usmilitary_sim_table.txt, replace
centiletable p_* using usmilitary_cent_table.txt, replace	

insheet using "usmilitary_sim_table.txt", tab clear
gen aid =.
replace		aid=	0	in		1
replace		aid=	1	in		2
replace		aid=	2	in		3
replace		aid=	3	in		4
replace		aid=	4	in		5
replace		aid=	5	in		6
replace		aid=	6	in		7
replace		aid=	7	in		8
replace		aid=	8	in		9
replace		aid=	9	in		10
replace		aid=	10	in		11
replace		aid=	11	in		12
replace		aid=	12	in		13
replace		aid=	13	in		14
replace		aid=	14	in		15
replace		aid=	15	in		16
replace		aid=	16	in		17
replace		aid=	17	in		18
replace		aid=	18	in		19
replace		aid=	19	in		20
replace		aid=	20	in		21
replace		aid=	21	in		22

rename v4 sd
save temp, replace

insheet using "usmilitary_cent_table.txt", tab clear
rename variable tem1
rename v1 variable
rename lowerbound tem2
rename tem1 lowerbound
rename upperbound tem3
rename tem2 upperbound
drop tem3
gen aid =.
replace		aid=	0	in		1
replace		aid=	1	in		2
replace		aid=	2	in		3
replace		aid=	3	in		4
replace		aid=	4	in		5
replace		aid=	5	in		6
replace		aid=	6	in		7
replace		aid=	7	in		8
replace		aid=	8	in		9
replace		aid=	9	in		10
replace		aid=	10	in		11
replace		aid=	11	in		12
replace		aid=	12	in		13
replace		aid=	13	in		14
replace		aid=	14	in		15
replace		aid=	15	in		16
replace		aid=	16	in		17
replace		aid=	17	in		18
replace		aid=	18	in		19
replace		aid=	19	in		20
replace		aid=	20	in		21
replace		aid=	21	in		22


merge 1:1 aid using temp

export delimited using "Predictions_usmilitary.csv"


********************************
****French Colonial History*****
********************************

clear 
use IIreadyforreplication.dta

*Run the model.

nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)


*Drop observations that are not in the model so that the quantities of interest are not calculated for those observations.

gen keep = 1 if e(sample)
drop if keep ~=1

*Save the data set as a temporary file named temp (you will retrieve this below).

save temp, replace


  set seed 17
  mat b = e(b)
  mat V = e(V)
  drawnorm b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b0, mean(b) cov(V) n(1000) clear


sum b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b0
  
  
*Merge the original data set (stored as temp) into the data set containing the simulated coefficients.

merge using temp


gen pmean = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace pmean = r(mean) in `i'
}


drop p_1-p_1000


gen p_0y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*0 + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_0y = r(mean) in `i'
}


drop p_1-p_1000

gen p_1y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*1 + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_1y = r(mean) in `i'
}


drop p_1-p_1000


save predictions1.dta

*pull out predicted counts and centiles
*do table program file
do "table_programs.do"
sumtable p_* using french_sim_table1.txt, replace
centiletable p_* using french_cent_table1.txt, replace	

insheet using "french_sim_table1.txt", tab clear
gen french =.
replace		french=	0	in		1
replace		french=	1	in		2

rename v4 sd
save temp, replace

insheet using "french_cent_table1.txt", tab clear
rename variable tem1
rename v1 variable
rename lowerbound tem2
rename tem1 lowerbound
rename upperbound tem3
rename tem2 upperbound
drop tem3
gen french =.
replace		french=	0	in		1
replace		french=	1	in		2


merge 1:1 french using temp

export delimited using "Predictions_frenchhistory.csv"

***********************
***HSIGOs & Violence***
***********************

clear 
use IIreadyforreplication.dta

*Run the model.

nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)


*Drop observations that are not in the model so that the quantities of interest are not calculated for those observations.

gen keep = 1 if e(sample)
drop if keep ~=1

*Save the data set as a temporary file named temp (you will retrieve this below).

save temp, replace


  set seed 17
  mat b = e(b)
  mat V = e(V)
  drawnorm b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b0, mean(b) cov(V) n(1000) clear


sum b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b0
  
  
*Merge the original data set (stored as temp) into the data set containing the simulated coefficients.

merge using temp


gen pmean = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace pmean = r(mean) in `i'
}


drop p_1-p_1000


gen p_0y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*12 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_0y = r(mean) in `i'
}


drop p_1-p_1000

gen p_1y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*13 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_1y = r(mean) in `i'
}


drop p_1-p_1000

gen p_2y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*14 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_2y = r(mean) in `i'
}


drop p_1-p_1000

gen p_3y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*15 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_3y = r(mean) in `i'
}


drop p_1-p_1000

gen p_4y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*16 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_4y = r(mean) in `i'
}


drop p_1-p_1000

gen p_5y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*17 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_5y = r(mean) in `i'
}


drop p_1-p_1000

gen p_6y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*18 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_6y = r(mean) in `i'
}


drop p_1-p_1000

gen p_7y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*19 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_7y = r(mean) in `i'
}


drop p_1-p_1000

gen p_8y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*20 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_8y = r(mean) in `i'
}


drop p_1-p_1000


save predictions2.dta

*pull out predicted counts and centiles
*do table program file
do "table_programs.do"
sumtable p_* using hsigov_sim_table.txt, replace
centiletable p_* using hsigov_cent_table.txt, replace	

insheet using "hsigov_sim_table.txt", tab clear
gen hsigo =.
replace		hsigo=	12	in		1
replace		hsigo=	13	in		2
replace		hsigo=	14	in		3
replace		hsigo=	15	in		4
replace		hsigo=	16	in		5
replace		hsigo=	17	in		6
replace		hsigo=	18	in		7
replace		hsigo=	19	in		8
replace		hsigo=	20	in		9

rename v4 sd
save temp, replace

insheet using "hsigov_cent_table.txt", tab clear
rename variable tem1
rename v1 variable
rename lowerbound tem2
rename tem1 lowerbound
rename upperbound tem3
rename tem2 upperbound
drop tem3
gen hsigo =.
replace		hsigo=	12	in		1
replace		hsigo=	13	in		2
replace		hsigo=	14	in		3
replace		hsigo=	15	in		4
replace		hsigo=	16	in		5
replace		hsigo=	17	in		6
replace		hsigo=	18	in		7
replace		hsigo=	19	in		8
replace		hsigo=	20	in		9


merge 1:1 hsigo using temp

export delimited using "Predictions_hsigosv.csv"


***********************
***HSIGOs & Nonviolence***
***********************

clear 
use IIreadyforreplication.dta

*Run the model.

nbreg postnonviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)


*Drop observations that are not in the model so that the quantities of interest are not calculated for those observations.

gen keep = 1 if e(sample)
drop if keep ~=1

*Save the data set as a temporary file named temp (you will retrieve this below).

save temp, replace


  set seed 17
  mat b = e(b)
  mat V = e(V)
  drawnorm b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b0, mean(b) cov(V) n(1000) clear


sum b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16 b0
  
  
*Merge the original data set (stored as temp) into the data set containing the simulated coefficients.

merge using temp


gen pmean = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*hsigo + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace pmean = r(mean) in `i'
}


drop p_1-p_1000


gen p_0y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*12 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_0y = r(mean) in `i'
}


drop p_1-p_1000

gen p_1y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*13 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_1y = r(mean) in `i'
}


drop p_1-p_1000

gen p_2y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*14 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_2y = r(mean) in `i'
}


drop p_1-p_1000

gen p_3y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*15 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_3y = r(mean) in `i'
}


drop p_1-p_1000

gen p_4y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*16 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_4y = r(mean) in `i'
}


drop p_1-p_1000

gen p_5y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*17 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_5y = r(mean) in `i'
}


drop p_1-p_1000

gen p_6y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*18 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_6y = r(mean) in `i'
}


drop p_1-p_1000

gen p_7y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*19 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_7y = r(mean) in `i'
}


drop p_1-p_1000

gen p_8y = .

 quietly forvalues i = 1/1000 {
    gen p_`i' = exp(b1[`i']*lnuseco_ + b2[`i']*lnusmil_ + b3[`i']*french + b4[`i']*20 + b5[`i']*logdp + b6[`i']*xpolity + b7[`i']*natural + b8[`i']*Nelda13 + b9[`i']*nelda45 + b10[`i']*serious + b11[`i']*repression + b12[`i']*latentm + b13[`i']*logpop + b14[`i']*electioncountry + b15[`i']*last + b16[`i']*_cons + b0[`i'])
    summarize p_`i', meanonly
    replace p_8y = r(mean) in `i'
}


drop p_1-p_1000


save predictions3.dta

*pull out predicted counts and centiles
*do table program file
do "table_programs.do"
sumtable p_* using hsigonv_sim_table3.txt, replace
centiletable p_* using hsigonv_cent_table3.txt, replace	

insheet using "hsigonv_sim_table3.txt", tab clear
gen hsigo =.
replace		hsigo=	12	in		1
replace		hsigo=	13	in		2
replace		hsigo=	14	in		3
replace		hsigo=	15	in		4
replace		hsigo=	16	in		5
replace		hsigo=	17	in		6
replace		hsigo=	18	in		7
replace		hsigo=	19	in		8
replace		hsigo=	20	in		9

rename v4 sd
save temp, replace

insheet using "hsigonv_cent_table3.txt", tab clear
rename variable tem1
rename v1 variable
rename lowerbound tem2
rename tem1 lowerbound
rename upperbound tem3
rename tem2 upperbound
drop tem3
gen hsigo =.
replace		hsigo=	12	in		1
replace		hsigo=	13	in		2
replace		hsigo=	14	in		3
replace		hsigo=	15	in		4
replace		hsigo=	16	in		5
replace		hsigo=	17	in		6
replace		hsigo=	18	in		7
replace		hsigo=	19	in		8
replace		hsigo=	20	in		9


merge 1:1 hsigo using temp

export delimited using "Predictions_hsigosnv.csv"

**************************************
**************APPENDIX****************
**************************************	 	

*Table A1
corr lnusmil_lagged lnuseco_lagged french hsigo

*Table A2
sum xpolity if lnusmil>12.8
sum xpolity if lnusmil<12.8

sum logdp if lnusmil>12.8
sum logdp if lnusmil<12.8

sum natural if lnusmil>12.8
sum natural if lnusmil<12.8

sum logdp if french==1
sum logdp if french==0

sum xpolity if french==1
sum xpolity if french==0

sum natural if french==1
sum natural if french==0

sum logdp if hsigo>16.6
sum logdp if hsigo<16.6

sum xpolity if hsigo>16.6
sum xpolity if hsigo<16.6

sum natural if hsigo>16.6
sum natural if hsigo<16.6

*Table A3
sum previol pren vp1 nvp1 postviolence postnon lnuseco_lagged lnusmil_lagged french hsigo electioncountry last Nelda13 logdp logpop latentm xpolity Nelda11 natural

*Figure A1 & A2
*See R file "mediation analysis.R"

*Table A4
clear 
use "IIreadyforreplication_GTDonly.dta"

*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N1) replace

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N2) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N3) append

*Table A5
clear
use "IIreadyforreplication_GEDonly.dta"

*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N4) replace

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N5) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N6) append

*Table A6
clear
use "IIreadyforreplication_ACLEDonly.dta"

*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N7) replace

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N8) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N9) append

*Table A7
clear 
use "IIreadyforreplication.dta"
*full models with outliers dropped
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last if postv<393, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N10) replace
nbreg pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last if postn<174, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N11) append
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if postv<393, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N12) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if postn<174, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N13) append
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if postv<393, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N14) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if postn<174, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N15) append

*Table A8
*entire time frame
nbreg totalv lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious Nelda11 repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N16) replace
nbreg totalnv lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious Nelda11 repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N17) append

*Table A9
clear
use "IIreadyforreplication_violentprotests.dta"
*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N18) replace
nbreg pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N19) append

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N20) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N21) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N22) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N23) append


*Table A10
clear
use "IIreadyforreplication.dta"

*ZINB

zinb previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, inf(last Nelda11) vce(cluster country) 
outreg2 using regtable.doc, word dec(3) ctitle(Model N24) replace
zinb pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, inf(last Nelda11) vce(cluster country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N25) append
 
zinb vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, inf(last) vce(cluster country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N26) append
zinb nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, inf(last serious) vce(cluster country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N27) append

zinb postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, inf(last serious) vce(cluster country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N28) append
zinb postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, inf(last serious) vce(cluster country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N29) append

*Table A11
*Civil wars dropped 

*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last if civil==0, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N30) replace
nbreg pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last if civil==0, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N31) append

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if civil==0, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N32) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if civil==0, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N33) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if civil==0, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N34) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last if civil==0, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N35) append

*Table A12-controlling for whether last election was violent
*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last previousviolentele, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N36) replace
nbreg pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last previousviolentele, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N37) append

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last previousviolentele, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N38) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last previousviolentele, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N39) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last previousviolentele, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N40) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last previousviolentele, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N41) append

*Table A13
*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural previousprotest Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N42) replace
nbreg pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural previousprotest Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N43) append

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural previousprotest Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N44) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural previousprotest Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N45) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural previousprotest Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N46) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural previousprotest Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N47) append


*Table A14
*election type
*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural presjoint Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N48) replace
nbreg pren lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural presjoint Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N49) append

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural presjoint Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N50) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural presjoint Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N51) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural presjoint Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N52) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural presjoint Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N53) append

*Table A15
*opposition vote gain

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda27 Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N54) replace
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda27 Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N55) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda27 Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N56) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural Nelda27 Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N57) append

*A16
*incumbant win 

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural incumbantwin Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N58) replace
nbreg nvp1 lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural incumbantwin Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N59) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural incumbantwin Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N60) append
nbreg postnon lnuseco_lagged lnusmil_lagged french hsigo logdp xpolity natural incumbantwin Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N61) append



*A17
*British Colonial History 
*three months before
nbreg previol lnuseco_lagged lnusmil_lagged french british hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N62) replace
nbreg pren lnuseco_lagged lnusmil_lagged french british hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N63) append

*one month after 
nbreg vp1 lnuseco_lagged lnusmil_lagged french british hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N64) append
nbreg nvp1 lnuseco_lagged lnusmil_lagged french british hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N65) append

*3 months after
nbreg postviolence lnuseco_lagged lnusmil_lagged british french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N66) append
nbreg postnon lnuseco_lagged lnusmil_lagged french british hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N67) append
*A18
*troops
*three months before
nbreg previol lnuseco_lagged lntroopsp french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N68) replace
nbreg pren lnuseco_lagged lntroopsp french hsigo logdp xpolity natural Nelda13 Nelda11 latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N69) append

*one month after 
nbreg vp1 lnuseco_lagged lntroopsp french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N70) append
nbreg nvp1 lnuseco_lagged lntroopsp french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N71) append

*3 months after
nbreg postviolence lnuseco_lagged lntroopsp french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N72) append
nbreg postnon lnuseco_lagged lntroopsp french hsigo logdp xpolity natural Nelda13 nelda45 serious repression latentm logpop electioncountry last, robust cluster(country)
outreg2 using regtable.doc, word dec(3) ctitle(Model N73) append

